package net.asgarli.ivault.api;

public enum ContentType {

	UNKNOWN_RAW(0), /* Unknown/raw/byte array container */
	FILE(1), /* Container that contains a file */
	WALLET(2), /* Wallet container*/
	;
	
	
	/**
	 * Constructor that takes the type code as argument
	 * @param i The type code of the Content
	 */
	ContentType(int typeCode) {
		this.typeCode = typeCode ;
	}
	
	/**
	 * Returns the integer type code.
	 * @return the integer type code.
	 */
	public int getTypeCode() {
		return typeCode;
	}
	
	/** The code of the Container type, for example, 0, 1, 3, etc. */
	private int typeCode;
	
	/** 
	 * Returns the instance of Content type that has a given type code.
	 * @param i the type code 
	 * @return ContentType instance matching type code.
	 */
	public ContentType getInstance(int i) {
		for (ContentType ct : ContentType.values()) {
			if (ct.getTypeCode() == i) return ct;
		}
		return null;
	}
	
	/** 
	 * Returns the instance of Content type that has a given type code.
	 * @param i the type code 
	 * @return Content instance matching type code.
	 * @throws NumberFormatException if the string cannot be parsed.
	 */
	public ContentType getInstance(String s) {
		return getInstance(Integer.parseInt(s));
	}
}
